package com.example.builder.exp2;

public class Circle extends GraphicShape {
    private boolean isCircle;
    private int radius;

    Circle(Builder builder) {
        super(builder);
        this.isCircle = builder.isCircle;
        this.radius = builder.radius;
    }

    public static class Builder extends GraphicShape.Builder<Builder> {
        boolean isCircle;
        int radius;

        public Builder(boolean ic, int r) {
            isCircle = ic;
            radius = r;
        }

        /**
         * 子类返回超类中声明类型的子类型，这称之为协变返回类型
         * 这样可以避免调用方法时进行强制类型转换
         * @return
         */
        @Override
        public Circle build() {
            return new Circle(self());
        }

        @Override
        Builder self() {
            return this;
        }
    }

    @Override
    public String toString() {
        return "Circle{" +
                "isCircle=" + isCircle +
                ", radius=" + radius +
                '}';
    }
}
